package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.ServiceDAO;
import com.zerosky.crm.po.ServiceSupport;
import com.zerosky.crm.service.ServiceSupportService;
import com.zerosky.crm.util.PageInfo;

@Service(value="serviceSupportService")
public class ServiceSupportServiceImpl implements ServiceSupportService {
	@Autowired
	private ServiceDAO ServiceDao;

	public List<ServiceSupport> getServiceList(Map map) {
		return ServiceDao.getServiceList(map);
	}

	/**
	 * 分页查询信息
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<ServiceSupport> getPageInfoList(Map map) {
		PageInfo<ServiceSupport> page = new PageInfo<ServiceSupport>();
		int begin = (((int) map.get("pageNo") - 1) * (int) map.get("pageSize"));
		// 写入数据
		map.put("pageNo", begin);
		List<ServiceSupport> list = ServiceDao.getServiceList(map);
		page.setList(list);
		int count = ServiceDao.countService(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public Integer saveOrUpdate(ServiceSupport Service, String operation) {
		if (operation.equals("新增")) {
			return ServiceDao.saveService(Service);
		} else if (operation.equals("修改")) {
			return ServiceDao.updateService(Service);
		}
		return 0;

	}

	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public Integer deleteService(String serviceId) {
		return ServiceDao.deleteServiceById(serviceId);

	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public ServiceSupport getServiceById(String serviceId) {
		return ServiceDao.getServiceById(serviceId);
	}

}
